// 从 itemElements 中 抽离所有的 imgElements 
export const getImgElements = (itemElements) => {
    const imgElements = []
    itemElements.forEach(item => {
        imgElements.push(...item.getElementsByTagName('img'))
    })
    return imgElements
}

// 获取所有图片的 src
export const getAllImg = (itemElements) => {
    return itemElements.map(item => item.src)
}
// 监听图片数组的加载完成
export const onComplateImgs = (imgs) => {
    return Promise.allSettled(
        imgs.map((img, index) => {
            return new Promise((resolve, reject) => {
                const imgObj = new Image();
                imgObj.src = img;
                imgObj.onload = () => resolve({ img, index });
                imgObj.onerror = () => reject(new Error(`Image load failed: ${img}`));
            });
        })
    );
};
// 返回最小高度的
export const getMinHeight = (columnHeightObj) => {
    const columnHeightArr = Object.values(columnHeightObj)
    return Math.min(...columnHeightArr)

}
// 返回最大高度的
export const getMaxHeight = (columnHeightObj) => {
    const columnHeightArr = Object.values(columnHeightObj)
    return Math.max(...columnHeightArr)

}
// 返回最小高度的列
export const getMinHeightColumn = (columnHeightObj) => {
    const minHeight = getMinHeight(columnHeightObj)
    return Object.keys(columnHeightObj).find(key => columnHeightObj[key] == minHeight)

}